<?php
class Entry_model extends CI_Model{

	function get_entries(){
		$q = $this->db->get('all_entries');
		
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
		
	}
	
	function add_new_entry($data){
		if($this->db->insert('entry',$data) == true){
			return true;
		}
	}
	
	function delete_entry(){
		$this->db->where('entry_id', $this->uri->segment(3));
		if($this->db->delete('entry') == true){
			return true;
		}
	}
	function update_entry($data){
		$this->db->where('entry_id',$data['entry_id']);
		
		if($this->db->update('entry',$data) == true){
			return true;
		}
	}
	
	function get_entry(){
		$this->db->where('entry_id',$this->uri->segment(3));
		$q = $this->db->get('all_entries');
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
	
	}
	function get_entry_content(){
		$this->db->where('entry_id',$this->uri->segment(3));
		$q = $this->db->get('published');
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
	
	}
	function get_entry_unpublish(){
		$q = $this->db->get('unpublished');
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
	
	}
	function get_entry_publish(){
		$q = $this->db->get('published');
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
	
	}
	function publish_entry(){
		$data = array(
			'entry_pubish' => 1
		);
		$this->db->where('entry_id',$this->uri->segment(3));
		if($this->db->update('entry',$data) == true){
			return true;
		}
	}
	function unpublish_entry(){
		$data = array(
			'entry_pubish' => 0
		);
		$this->db->where('entry_id',$this->uri->segment(3));
		if($this->db->update('entry',$data) == true){
			return true;
		}
	}
	function get_entry_category(){
		$this->db->where('entry_category_parent',$this->uri->segment(3));
		$q = $this->db->get('published');
		if($q->num_rows() > 0){
			foreach ($q->result() as $row){
				$data[] = $row;
			}
			return $data;
		}
	
	}
	
}